﻿var totalLogin = {
    _loginUrl: '../Ajax/Login.aspx',

    setWrong: function (msg)
    {
        $('#username_label').hide();
        $('#password_label').hide();
        $('#cwts').html(msg + '<em></em>').show();
    },
    setInit: function ()
    {
        $('#username_label').show();
        $('#password_label').show();
        $('#cwts').hide();
    },
    login: function ()
    {
        this.setInit();
        var username = $('#username').val();
        var password = $('#password').val();
        if ($('#expire')[0].checked)
        {
            var expire = $('#expire').val();
        } else
        {
            var expire = 0;
        }

        if ($.trim(username) == '')
        {
            this.setWrong('用户名和密码不能为空');
            return false;
        }
        if ($.trim(password) == '')
        {
            this.setWrong('用户名和密码不能为空');
            return false;
        }
        $.ajax({
            type: "GET",
            url: this._loginUrl,
            data: ({ username: username, password: password, expire: expire, code: Math.random() }),
            dataType: 'html',
            success: function (data)
            {

                if (data == 'succ')
                {
                    window.returnValue = 'succ';
                    window.close();
                    return false;
                    //window.location.href = 'Index.aspx';
                    // window.location.href = document.URL;
                }
                else if (data == 'jinyong')
                {
                    totalLogin.setWrong('账号被禁用，请联系管理员');
                }
                else
                {
                    totalLogin.setWrong('用户名或密码不正确');
                }
            }
        });
    }

}
